<?php
class AuthAction extends Action {
	public function login() {
		if (isset ( $_SESSION ['top_session'] ))
			$this->redirect ( '/' );
		
		echo '<p><a href="' . TAO_OAUTH_LOGIN_URL . '">LOGIN</a></p>';
	}
	public function loginout() {
		unset ( $_SESSION ['top_session'] );
		unset ( $_SESSION ['seller_nick'] );
		unset ( $_SESSION ['role'] );
		$this->success("已安全退出系统...", U('login') );
	}
	public function userInit( $user ) {
		if ($user ['user_seller_get_response'] ['user'] ['user_id'] && $user ['user_seller_get_response'] ['user'] ['nick']) {
			$seller = M ( 'seller' )->where ( "user_id='{$user['user_seller_get_response']['user']['user_id']}' AND nick='{$user['user_seller_get_response']['user']['nick']}' " )->find ();
			if (! isset ( $seller )) {
				$newseller ['user_id'] = $user ['user_seller_get_response'] ['user'] ['user_id'];
				$newseller ['nick'] = $user ['user_seller_get_response'] ['user'] ['nick'];
				$newseller ['addtime'] = date('Y-m-d H:i:s');
				$newseller ['paybalance'] = '0.00';
				M ( 'seller' )->add ( $newseller );
			}
			$_SESSION['seller_nick'] = $user ['user_seller_get_response'] ['user'] ['nick'];
			$_SESSION['role'] = $seller[role];
			return true;
		}
	}
}